package graph;

import java.util.Collection;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import java.util.SortedMap;
import java.util.TreeMap;
import java.util.Map.Entry;

public class Vertex<O, W> {

	private WeightedDirectedGraph<O, W> graph;
	private O object;

	private SortedMap<W, Vertex<O, W>> neighbours = new TreeMap<W, Vertex<O, W>>();

	public Vertex(WeightedDirectedGraph<O, W> graph, O object) {
		this.graph = graph;
		this.object = object;
	}

	public O getObject() {
		return object;
	}

	public void addSide(Vertex<O, W> to, W weight) {
		neighbours.put(weight, to);
	}

	public Collection<Vertex<O, W>> getNeighbours() {
		return neighbours.values();
	}

	public W getWeight(O to) {
		return null;
	}

	public String toString() {
		String ret = "";
		ret += object;
		Set<Map.Entry<W, Vertex<O, W>>> set = neighbours.entrySet();
		Iterator<Entry<W, Vertex<O, W>>> i = set.iterator();
		while (i.hasNext()) {
			Map.Entry<W, Vertex<O, W>> me = i.next();
			ret += "\n	" + me.getKey() + "|->" + me.getValue().getObject();
		}
		return ret;
	}

}
